Add tests for keymap-based-bindings
authorJustin Burkett <justin@burkett.cc>
Mon, 19 Oct 2020 15:15:35 +0000 (11:15 -0400)
committerJustin Burkett <justin@burkett.cc>
Mon, 19 Oct 2020 15:15:35 +0000 (11:15 -0400)
which-key-tests.el

index f9fac65c73b3cb9763063d489a25479de9cdd161..1611d51cc04c1d90f2765cd002bfd1dcf076fc30 100644 (file)
 (require 'which-key)
 (require 'ert)
 
-(ert-deftest which-key-test-prefix-declaration ()
+(ert-deftest which-key-test--keymap-based-bindings ()
+  (let ((map (make-sparse-keymap))
+        (emacs-lisp-mode-map (copy-keymap emacs-lisp-mode-map)))
+    (emacs-lisp-mode)
+    (define-key map "x" 'ignore)
+    (define-key emacs-lisp-mode-map "\C-c\C-a" 'complete)
+    (define-key emacs-lisp-mode-map "\C-c\C-b" map)
+    (which-key-add-keymap-based-replacements emacs-lisp-mode-map
+      "C-c C-a" '("mycomplete" . complete)
+      "C-c C-b" "mymap")
+    (should (equal
+             (which-key--maybe-replace '("C-c C-a" . "complete"))
+             '("C-c C-a" . "mycomplete")))
+    (should (equal
+             (which-key--maybe-replace '("C-c C-b" . ""))
+             '("C-c C-b" . "mymap")))))
+
+(ert-deftest which-key-test--prefix-declaration ()
   "Test `which-key-declare-prefixes' and
 `which-key-declare-prefixes-for-mode'. See Bug #109."
   (let* ((major-mode 'test-mode)